<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>EF code first简单示例 | Is2</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="EF code first简单示例">
<meta property="og:type" content="article">
<meta property="og:title" content="EF code first简单示例">
<meta property="og:url" content="/2016/04/13/EF-code-first-simple-example/index.html">
<meta property="og:site_name" content="Is2">
<meta property="og:description" content="EF code first简单示例">
<meta property="og:image" content="http://ww1.sinaimg.cn/mw690/c55a7aeegw1f2v56p11fvj20m80h8tc1.jpg">
<meta property="og:image" content="http://ww2.sinaimg.cn/mw690/c55a7aeegw1f2v5ax49q3j207x0ec74j.jpg">
<meta property="og:image" content="http://ww4.sinaimg.cn/mw690/c55a7aeegw1f2v5pqpkftj218g0oeq68.jpg">
<meta property="og:image" content="http://ww4.sinaimg.cn/mw690/c55a7aeegw1f2v6lnz9r9j20at0823ym.jpg">
<meta property="og:image" content="http://ww2.sinaimg.cn/mw690/c55a7aeegw1f2v8j7u70cj20dd07ggm1.jpg">
<meta property="og:image" content="http://ww1.sinaimg.cn/mw690/c55a7aeegw1f2v8ojeym7j20g70610sv.jpg">
<meta property="og:updated_time" content="2016-10-08T12:45:59.717Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="EF code first简单示例">
<meta name="twitter:description" content="EF code first简单示例">
  
    <link rel="alternate" href="/atom.xml" title="Is2" type="application/atom+xml">
  
  
    <link rel="icon" href="img/logo.ico">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
<!-- 新 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css">

  

  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" integrity="sha384-XdYbMnZ/QjLh6iI4ogqCTaIjrFk87ip+ekIjefZch0Y+PvJ8CDYtEs1ipDmPorQ+" crossorigin="anonymous">

  <link rel="stylesheet" href="/css/styles.css" type="text/css">
  

  
  <!--百度统计代码-->
  <script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "//hm.baidu.com/hm.js?37b51d72e2b91d854971620de6fef9bc";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>
<!--百度自动推送代码-->
<script>
(function(){
    var bp = document.createElement('script');
    bp.src = '//push.zhanzhang.baidu.com/push.js';
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>
<script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js">
</script>
</head>

<body>
  <nav class="navbar navbar-inverse">
  <div class="container">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#main-menu-navbar" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="main-menu-navbar">
      <ul class="nav navbar-nav">
        
          <li><a class=""
                 href="/index.html">首页</a></li>
        
          <li><a class=""
                 href="/categories/文集/">文集</a></li>
        
          <li><a class=""
                 href="/archives/">归档</a></li>
        
          <li><a class=""
                 href="/resource/">资源</a></li>
        
          <li><a class=""
                 href="/about/">关于</a></li>
        
        <li> <a href="/atom.xml">RSS</a> </li> 
      </ul>

      <!--
      <ul class="nav navbar-nav navbar-right">
        
          <li><a href="/atom.xml" title="RSS Feed"><i class="fa fa-rss"></i></a></li>
        
      </ul>
      -->
    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>

  <div class="container">
    <div class="blog-header">
  <h1 class="blog-title">Is2</h1>
  
    <p class="lead blog-description">我只想做的更好</p>
  
</div>

    <div class="row">
        <div class="col-sm-8 blog-main">
          <article id="post-EF-code-first-simple-example" class="article article-type-post" itemscope itemprop="blogPost">

  <header class="article-header">
    
  
    <h1 class="article-title" itemprop="name">
      EF code first简单示例
    </h1>
  


  </header>

  <div class="article-meta">
    <div class="article-datetime">
  <a href="/2016/04/13/EF-code-first-simple-example/" class="article-date"><time datetime="2016-04-13T12:35:53.000Z" itemprop="datePublished">2016-04-13</time></a>
</div>

    
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/Asp-Net-MVC/">Asp.Net MVC</a>
  </div>

  </div>
  <div class="article-inner">

    <div class="article-entry" itemprop="articleBody">
      
        <p>　　一个简单的MVC5+EF6小demo，演示mvc和ef的简单编写流程。</p>
<h2 id="创建项目">创建项目</h2><p>　　1、选择.Net Farmework版本为4.5以上的，这里我选择4.5.2<br>　　2、选择模板，选择<strong>Empty</strong>，勾选MVC引用：<img src="http://ww1.sinaimg.cn/mw690/c55a7aeegw1f2v56p11fvj20m80h8tc1.jpg" alt=""><a id="more"></a><br>　　可以看到VS自动帮我们添加了asp.net MVC默认约定的文件夹，按照asp.net MVC的约定大于配置的原则，不要随意改变文件夹的名字，也不要将文件随意添加，不然可能导致程序出错。<img src="http://ww2.sinaimg.cn/mw690/c55a7aeegw1f2v5ax49q3j207x0ec74j.jpg" alt=""><br>　　关于基本项目文件的说明：<br>　　<code>App_Start</code>：一些全局的配置类，配合<code>Global</code>使用。<br>　　<code>Controllers</code>：存放MVC控制器的文件夹。<br>　　<code>Models</code>：存放数据模型(class)文件夹。<br>　　<code>Views</code>：存放视图的文件夹。</p>
<h2 id="添加EF组件">添加EF组件</h2><p>　　EntityFarmework是作为组件的形式存在的，要使用EntityFarmework需要添加它的引用。<br>　　1、使用Nuget添加EF：右击引用==&gt;管理NuGet程序包，会弹出NuGet管理界面。<br>　　2、点击“浏览”按钮，可以看到“EntityFramework”作为常用组件会排列在第一位，选择后，点击右边的“安装”按钮即可进行安装。<img src="http://ww4.sinaimg.cn/mw690/c55a7aeegw1f2v5pqpkftj218g0oeq68.jpg" alt=""></p>
<h2 id="添加User数据模型，并且使用code_first自动生成数据库">添加User数据模型，并且使用code first自动生成数据库</h2><p>　　1、在“Models”文件夹中添加一个名为<code>User</code>的类，并添加以下内容：<br><figure class="highlight cs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">int</span> Id &#123; <span class="keyword">get</span>; <span class="keyword">set</span>; &#125;</span><br><span class="line"></span><br><span class="line">[Required(ErrorMessage = <span class="string">"用户名必填"</span>)]</span><br><span class="line">[Display(Name = <span class="string">"用户名"</span>)]</span><br><span class="line"><span class="keyword">public</span> <span class="keyword">string</span> Name &#123; <span class="keyword">get</span>; <span class="keyword">set</span>; &#125;</span><br><span class="line"></span><br><span class="line">[Required(ErrorMessage=<span class="string">"密码必填"</span>)]</span><br><span class="line">[Display(Name=<span class="string">"密码"</span>)]</span><br><span class="line"><span class="keyword">public</span> <span class="keyword">string</span> Pwd &#123; <span class="keyword">get</span>; <span class="keyword">set</span>; &#125;</span><br></pre></td></tr></table></figure></p>
<p>　　注：需要添加一个命名空间<code>System.ComponentModel.DataAnnotations</code>，代码中的特性标签是作为数据注解使用的，关于数据注解，在下一篇中总结。</p>
<p>　　2、添加数据库上下文类：<br>　　在“Models”文件夹中添加一个名为<code>DbEntities</code>的类作为数据库上下文类，该类需要继承<code>DbContext</code>类。然后添加如下代码：<br><figure class="highlight cs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title">DbEntities</span>:<span class="title">DbContext</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="comment">//base中的字符串为web.config中设置的数据库连接字符串名</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="title">DbEntities</span>(<span class="params"></span>):<span class="title">base</span>(<span class="params"><span class="string">"name=SQLConnString"</span></span>)</span><br><span class="line">    </span>&#123;</span><br><span class="line">        <span class="comment">//表示创建数据库的方式</span></span><br><span class="line">        Database.SetInitializer&lt;DbEntities&gt;(<span class="keyword">new</span> CreateDatabaseIfNotExists&lt;DbEntities&gt;());</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">//存储User数据的属性</span></span><br><span class="line">    <span class="keyword">public</span> DbSet&lt;User&gt; User &#123; <span class="keyword">get</span>; <span class="keyword">set</span>; &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>　　3、配置数据库连接字符串<br>　　打开“web.config”文件，添加数据库连接字符串，比如：<br>　　因为目前为止还没有创建数据库，所以这里指定数据库名称时，可以随意起一个不重复的名字即可，创建时，就会自动按照该名称创建数据库。<br>　　同时注意，连接字符串的<code>name</code>属性的值和数据库上下文中<code>base</code>的值要一致。<br><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="title">connectionStrings</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="title">add</span> <span class="attribute">name</span>=<span class="value">"SQLConnString"</span> <span class="attribute">providerName</span>=<span class="value">"System.Data.SqlClient"</span> <span class="attribute">connectionString</span>=<span class="value">"Data Source=.;Initial Catalog=MVC5_Test;Persist Security Info=True;User ID=sa;Password=sa"</span> /&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="title">connectionStrings</span>&gt;</span></span><br></pre></td></tr></table></figure></p>
<p>　　4、使用EF数据迁移创建数据库<br>　　依次点击：工具==&gt;NuGet包管理器==&gt;程序包管理控制台，打开power shell窗口。<br>　　输入：<br>　　　　<code>Enable-Migrations</code>：表示开启该项目的数据迁移功能，只需运行依次，以后迁移数据时，不需要再运行该命令。<br>　　　　<code>Add-Migration migrationName</code>：添加迁移命令，需要给本次迁移起一个名字(如migrationName)，这时还没有开始迁移，只是打上了迁移的标记。<br>　　　　<code>Update-Database</code>：将迁移更新到数据库中。<br>　　三条命令全部成功执行后，不出意外的话，数据库中应该已经创建了相应的数据库、表、字段：<img src="http://ww4.sinaimg.cn/mw690/c55a7aeegw1f2v6lnz9r9j20at0823ym.jpg" alt=""><br>　　同时，项目中也为我们自动添加了一个名为“Migrations”的文件夹，里面有两个文件，分别是数据迁移的配置类(Configuration)、数据迁移的内容(xxxxx_migrationName)。</p>
<h2 id="编写简单的登录页面">编写简单的登录页面</h2><p>　　我们可以直接在数据库中添加一条用户登录的数据，Name=admin,Pwd=123456<br>　　1、添加控制器：<br>　　　　在“Controllers”文件夹右击，添加==&gt;控制器，在弹出的窗口中选择“MVC5控制器 空”，然后起名为<code>HomeController</code>。<br>　　2、添加首页视图：<br>　　　　可以看到，自动为我们生成了一个<code>Index</code>方法，光标停在<code>Index</code>上面，然后鼠标右击，在弹出的菜单中选择“添加视图”，然后在弹出窗口中不修改视图的名字(按照约定，视图的名字必须和控制器方法名一致)，去除“使用布局页”前面的对勾(关于如何使用布局页将在另一篇博客中总结)，点击添加。<br>　　3、在Index视图中添加表单：<br>　　　　VS帮我们生成了一个基础的Razor模板，我们在<code>&lt;body&gt;&lt;/body&gt;</code>中添加表单内容：<br>　　关于@html辅助方法，在前面的<a href="http://www.hais2.com/2015/08/02/HTML%E8%BE%85%E5%8A%A9%E6%96%B9%E6%B3%95/" target="_blank" rel="external">博客</a>中简单总结了一下。<br>　　在页面开头我们还需要引入在Razor中使用的数据模型的完全限定名，使用<code>@model</code>引入，比如<code>@model Mvc5_EF6_Demo.Models.User</code><br><figure class="highlight less"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable">@using</span> (Html.<span class="function">BeginForm</span>(<span class="string">"Index"</span>, <span class="string">"Home"</span>))</span><br><span class="line">&#123;</span><br><span class="line">       <span class="variable">@Html</span>.<span class="function">ValidationSummary</span>(true)</span><br><span class="line">       &lt;h1&gt;请输入用户名密码登陆&lt;/h1&gt;</span><br><span class="line">       <span class="variable">@Html</span>.<span class="function">LabelFor</span>(model =&gt; model.Name)</span><br><span class="line">       <span class="variable">@Html</span>.<span class="function">TextBoxFor</span>(model =&gt; model.Name)</span><br><span class="line">       <span class="variable">@Html</span>.<span class="function">ValidationMessageFor</span>(model =&gt; model.Name)</span><br><span class="line">       &lt;br /&gt;</span><br><span class="line">       <span class="variable">@Html</span>.<span class="function">LabelFor</span>(model =&gt; model.Pwd)</span><br><span class="line">       <span class="variable">@Html</span>.<span class="function">TextBoxFor</span>(model =&gt; model.Pwd)</span><br><span class="line">       <span class="variable">@Html</span>.<span class="function">ValidationMessageFor</span>(model =&gt; model.Pwd)</span><br><span class="line">       &lt;br /&gt;</span><br><span class="line">       &lt;input type=<span class="string">"submit"</span> value=<span class="string">"登陆"</span> /&gt;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>　　4、添加登录事件处理方法：<br>　　在<code>HomeController</code>控制器中创建一个名为<code>Index</code>的方法，因为表单的发送地址执行了Index方法，但是现在又两个Index方法，这是程序不允许的，需要进行处理。<br>　　由于表单是post请求发送的，在接收表单的Index方法上面写上一个特性标签<code>[HttpPost]</code>，表示该方法只响应post请求，然后接收参数为<code>User</code>类型的一个参数，代码如下：<br><figure class="highlight stata"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">[HttpPost]</span><br><span class="line">public ActionResult <span class="literal">Index</span>(User user)<span class="comment">//将表单中的输入自动组成User类，传递到Login方法</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="comment">//判断表单模型是否验证成功</span></span><br><span class="line">    <span class="keyword">if</span> (!ModelState.IsValid)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">View</span>(user);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//如果表单验证成功</span></span><br><span class="line">    <span class="comment">//创建数据上下文类对象</span></span><br><span class="line">    DbEntities <span class="keyword">db</span> = new DbEntities();</span><br><span class="line">    <span class="comment">//查找User表中的所有数据,转换成List类型</span></span><br><span class="line">    <span class="keyword">var</span> userInfo = <span class="keyword">db</span>.User.Select(s =&gt; s).ToList();</span><br><span class="line">    <span class="comment">//简单的判断一下输入和数据库是否相同</span></span><br><span class="line">    <span class="keyword">if</span> (userInfo[0].Name==user.Name&amp;&amp;userInfo[0].<span class="keyword">Pwd</span>==user.<span class="keyword">Pwd</span>)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="comment">//跳转到登录成功的Action</span></span><br><span class="line">        <span class="keyword">return</span> RedirectToAction(<span class="string">"LoginOk"</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">View</span>(user);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>　　5、添加登录成功视图：<br>　　在<code>HomeController</code>控制器中增加一个<code>LoginOk</code>方法并且添加视图，用来展示登录成功页面</p>
<h2 id="测试">测试</h2><p>　　启动项目，测试：<br>　　1、我们少填一个字段：<br>　　<img src="http://ww2.sinaimg.cn/mw690/c55a7aeegw1f2v8j7u70cj20dd07ggm1.jpg" alt=""><br>　　可以看到，不填写的话，就会显示相应的提示，因为我们在数据模型中添加了<code>[Required]</code>特性标签，就是必填的意思，然后在提交到Action中时，使用<code>ModelState.IsValid</code>进行判断。<br>　　2、验证成功：<br>　　<img src="http://ww1.sinaimg.cn/mw690/c55a7aeegw1f2v8ojeym7j20g70610sv.jpg" alt=""><br>　　3、验证失败：<br>　　暂时没有验证，所以会跳转到Index页面。</p>
<p><a href="http://pan.baidu.com/s/1boCP2RP" target="_blank" rel="external">代码下载</a></p>

      
    </div>

    
      

    
    <br/><br/>
<!--baidu share-->

<div class="bdsharebuttonbox"><a class="bds_more" href="#" data-cmd="more">分享到：</a><a title="分享到新浪微博" class="bds_tsina" href="#" data-cmd="tsina">新浪微博</a><a title="分享到微信" class="bds_weixin" href="#" data-cmd="weixin">微信</a><a title="分享到QQ空间" class="bds_qzone" href="#" data-cmd="qzone">QQ空间</a><a title="分享到QQ好友" class="bds_sqq" href="#" data-cmd="sqq">QQ好友</a></div>
<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{"bdSize":16}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
  
<!--baidu share-->
    <footer class="article-footer">
      <a data-url="/2016/04/13/EF-code-first-simple-example/" data-id="ciqvzmhtm0066csvl821uecj5" class="article-share-link">
        <i class="fa fa-share"></i> Share
      </a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Asp-Net-MVC/">Asp.Net MVC</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/EntityFramework/">EntityFramework</a></li></ul>


    </footer>
  </div>
  
    
<ul id="article-nav" class="nav nav-pills nav-justified">
  
  <li role="presentation">
    <a href="/2016/03/28/Git-command-summary/" id="article-nav-older" class="article-nav-link-wrap">
      <i class="fa fa-chevron-left pull-left"></i>
      <span class="article-nav-link-title">git常用命令总结</span>
    </a>
  </li>
  
  
  <li role="presentation">
    <a href="/2016/04/20/Guid-ToString-overload-of-the-format/" id="article-nav-newer" class="article-nav-link-wrap">
      <span class="article-nav-link-title">Guid.ToString()的格式化重载</span>
      <i class="fa fa-chevron-right pull-right"></i>
    </a>
  </li>
  
</ul>


  
</article>


<section id="comments">
  <div id="disqus_thread">
    <!-- 多说评论框 start -->
	<div class="ds-thread" data-thread-key="2016/04/13/EF-code-first-simple-example/" data-title="EF code first简单示例" data-url="/2016/04/13/EF-code-first-simple-example/"></div>
<!-- 多说评论框 end -->
<!-- 多说公共JS代码 start (一个网页只需插入一次) -->
<script type="text/javascript">
var duoshuoQuery = {short_name:"hais2"};
	(function() {
		var ds = document.createElement('script');
		ds.type = 'text/javascript';ds.async = true;
		ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
		ds.charset = 'UTF-8';
		(document.getElementsByTagName('head')[0] 
		 || document.getElementsByTagName('body')[0]).appendChild(ds);
	})();
	</script>
<!-- 多说公共JS代码 end -->
  </div>
</section>


        </div>
        <div class="col-sm-3 col-sm-offset-1 blog-sidebar">
          
  <div class="sidebar-module sidebar-module-inset">
<a style="text-decoration:none" title="有本事点我一下试试.." href='javascript:(function() {
	function c() {
		var e = document.createElement("link");
		e.setAttribute("type", "text/css");
		e.setAttribute("rel", "stylesheet");
		e.setAttribute("href", f);
		e.setAttribute("class", l);
		document.body.appendChild(e)
	}
 
	function h() {
		var e = document.getElementsByClassName(l);
		for (var t = 0; t < e.length; t++) {
			document.body.removeChild(e[t])
		}
	}
 
	function p() {
		var e = document.createElement("div");
		e.setAttribute("class", a);
		document.body.appendChild(e);
		setTimeout(function() {
			document.body.removeChild(e)
		}, 100)
	}
 
	function d(e) {
		return {
			height : e.offsetHeight,
			width : e.offsetWidth
		}
	}
 
	function v(i) {
		var s = d(i);
		return s.height > e && s.height < n && s.width > t && s.width < r
	}
 
	function m(e) {
		var t = e;
		var n = 0;
		while (!!t) {
			n += t.offsetTop;
			t = t.offsetParent
		}
		return n
	}
 
	function g() {
		var e = document.documentElement;
		if (!!window.innerWidth) {
			return window.innerHeight
		} else if (e && !isNaN(e.clientHeight)) {
			return e.clientHeight
		}
		return 0
	}
 
	function y() {
		if (window.pageYOffset) {
			return window.pageYOffset
		}
		return Math.max(document.documentElement.scrollTop, document.body.scrollTop)
	}
 
	function E(e) {
		var t = m(e);
		return t >= w && t <= b + w
	}
 
	function S() {
		var e = document.createElement("audio");
		e.setAttribute("class", l);
		e.src = i;
		e.loop = false;
		e.addEventListener("canplay", function() {
			setTimeout(function() {
				x(k)
			}, 500);
			setTimeout(function() {
				N();
				p();
				for (var e = 0; e < O.length; e++) {
					T(O[e])
				}
			}, 15500)
		}, true);
		e.addEventListener("ended", function() {
			N();
			h()
		}, true);
		e.innerHTML = " <p>If you are reading this, it is because your browser does not support the audio element. We recommend that you get a new browser.</p> <p>";
		document.body.appendChild(e);
		e.play()
	}
 
	function x(e) {
		e.className += " " + s + " " + o
	}
 
	function T(e) {
		e.className += " " + s + " " + u[Math.floor(Math.random() * u.length)]
	}
 
	function N() {
		var e = document.getElementsByClassName(s);
		var t = new RegExp("\\b" + s + "\\b");
		for (var n = 0; n < e.length; ) {
			e[n].className = e[n].className.replace(t, "")
		}
	}
 
	var e = 30;
	var t = 30;
	var n = 350;
	var r = 350;
	var i = "//s3.amazonaws.com/moovweb-marketing/playground/harlem-shake.mp3";
	var s = "mw-harlem_shake_me";
	var o = "im_first";
	var u = ["im_drunk", "im_baked", "im_trippin", "im_blown"];
	var a = "mw-strobe_light";
	var f = "//s3.amazonaws.com/moovweb-marketing/playground/harlem-shake-style.css";
	var l = "mw_added_css";
	var b = g();
	var w = y();
	var C = document.getElementsByTagName("*");
	var k = null;
	for (var L = 0; L < C.length; L++) {
		var A = C[L];
		if (v(A)) {
			if (E(A)) {
				k = A;
				break
			}
		}
	}
	if (A === null) {
		console.warn("Could not find a node of the right size. Please try a different page.");
		return
	}
	c();
	S();
	var O = [];
	for (var L = 0; L < C.length; L++) {
		var A = C[L];
		if (v(A)) {
			O.push(A)
		}
	}
})()'>
    <h4>Hi</h4>
</a>

  
  <h5>我是海建东,欢迎访问我的博客.</h5>

</div>


  
  <div class="sidebar-module">
    <h4>分类</h4>
    <ul class="sidebar-module-list"><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/ASP-NET/">ASP.NET</a><span class="sidebar-module-list-count">4</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/ASP-NET-Web-API/">ASP.NET Web API</a><span class="sidebar-module-list-count">1</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/Asp-Net-MVC/">Asp.Net MVC</a><span class="sidebar-module-list-count">3</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/Git/">Git</a><span class="sidebar-module-list-count">3</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/Hexo/">Hexo</a><span class="sidebar-module-list-count">10</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/SQL/">SQL</a><span class="sidebar-module-list-count">8</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/UWP/">UWP</a><span class="sidebar-module-list-count">2</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/Umbraco/">Umbraco</a><span class="sidebar-module-list-count">11</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/c/">c#</a><span class="sidebar-module-list-count">18</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/前端开发/">前端开发</a><span class="sidebar-module-list-count">3</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/文集/">文集</a><span class="sidebar-module-list-count">12</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/categories/设计模式/">设计模式</a><span class="sidebar-module-list-count">6</span></li></ul>
  </div>



  
  <div class="sidebar-module">
    <h4>标签</h4>
    <ul class="sidebar-module-list"><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/tags/ASP-NET/">ASP.NET</a><span class="sidebar-module-list-count">1</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/tags/ASP-NET-Core/">ASP.NET Core</a><span class="sidebar-module-list-count">2</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/tags/ASP-NET-Web-API笔记/">ASP.NET Web API笔记</a><span class="sidebar-module-list-count">1</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/tags/AngularJS/">AngularJS</a><span class="sidebar-module-list-count">2</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/tags/Asp-Net-MVC/">Asp.Net MVC</a><span class="sidebar-module-list-count">3</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/tags/EntityFramework/">EntityFramework</a><span class="sidebar-module-list-count">1</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/tags/Git学习/">Git学习</a><span class="sidebar-module-list-count">3</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/tags/Hexo博客搭建/">Hexo博客搭建</a><span class="sidebar-module-list-count">10</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/tags/SQL-Server/">SQL Server</a><span class="sidebar-module-list-count">8</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/tags/UWP学习笔记/">UWP学习笔记</a><span class="sidebar-module-list-count">2</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/tags/Umbraco入门/">Umbraco入门</a><span class="sidebar-module-list-count">11</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/tags/WebForm/">WebForm</a><span class="sidebar-module-list-count">1</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/tags/c-基础知识/">c#基础知识</a><span class="sidebar-module-list-count">6</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/tags/c-学习笔记/">c#学习笔记</a><span class="sidebar-module-list-count">12</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/tags/jQuery/">jQuery</a><span class="sidebar-module-list-count">1</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/tags/影评：其实就是观后感/">影评：其实就是观后感</a><span class="sidebar-module-list-count">4</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/tags/设计模式学习笔记/">设计模式学习笔记</a><span class="sidebar-module-list-count">6</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/tags/转载/">转载</a><span class="sidebar-module-list-count">7</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/tags/随笔/">随笔</a><span class="sidebar-module-list-count">8</span></li></ul>
  </div>



  
  <div class="sidebar-module">
    <h4>归档</h4>
    <ul class="sidebar-module-list"><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2016/07/">七月 2016</a><span class="sidebar-module-list-count">4</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2016/05/">五月 2016</a><span class="sidebar-module-list-count">3</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2016/04/">四月 2016</a><span class="sidebar-module-list-count">2</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2016/03/">三月 2016</a><span class="sidebar-module-list-count">14</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2016/02/">二月 2016</a><span class="sidebar-module-list-count">6</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2016/01/">一月 2016</a><span class="sidebar-module-list-count">23</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2015/10/">十月 2015</a><span class="sidebar-module-list-count">2</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2015/09/">九月 2015</a><span class="sidebar-module-list-count">1</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2015/08/">八月 2015</a><span class="sidebar-module-list-count">1</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2015/07/">七月 2015</a><span class="sidebar-module-list-count">2</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2015/06/">六月 2015</a><span class="sidebar-module-list-count">4</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2015/05/">五月 2015</a><span class="sidebar-module-list-count">7</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2015/04/">四月 2015</a><span class="sidebar-module-list-count">6</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2015/03/">三月 2015</a><span class="sidebar-module-list-count">2</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2015/02/">二月 2015</a><span class="sidebar-module-list-count">1</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2015/01/">一月 2015</a><span class="sidebar-module-list-count">1</span></li><li class="sidebar-module-list-item"><a class="sidebar-module-list-link" href="/archives/2014/11/">十一月 2014</a><span class="sidebar-module-list-count">2</span></li></ul>
  </div>



  <!---->
  <div class="sidebar-module">
    <h4>最近访客</h4>
    <!--<ul class="sidebar-module-list">
      
        <li>
          <a href="/2016/07/19/Journey-Under-the-Midnight-Sun/">行走在白昼的夜里</a>
        </li>
      
        <li>
          <a href="/2016/07/18/Hexo-misspelled-tag/">Hexo标签分类写错的处理</a>
        </li>
      
        <li>
          <a href="/2016/07/17/Value-types-and-reference-types/">值类型和引用类型</a>
        </li>
      
        <li>
          <a href="/2016/07/17/Fiddler-caught-analysis-API/">使用Fiddler抓包分析API</a>
        </li>
      
        <li>
          <a href="/2016/05/14/Hexo-Getting-Started-1/">8、使用SSH方式部署博客</a>
        </li>
      
    </ul>
    
    <div class="ds-recent-visitors" data-num-items="12" data-avatar-size="28" id="ds-recent-visitors"></div>
-->
<!-- 多说最新评论 start -->
	<div class="ds-recent-comments" data-num-items="5" data-show-avatars="1" data-show-time="1" data-show-title="1" data-show-admin="0" data-excerpt-length="20"></div>
<!-- 多说最新评论 end -->
<!-- 多说公共JS代码 start (一个网页只需插入一次) -->
<script type="text/javascript">
var duoshuoQuery = {short_name:"hais2"};
	(function() {
		var ds = document.createElement('script');
		ds.type = 'text/javascript';ds.async = true;
		ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
		ds.charset = 'UTF-8';
		(document.getElementsByTagName('head')[0] 
		 || document.getElementsByTagName('body')[0]).appendChild(ds);
	})();
	</script>
<!-- 多说公共JS代码 end -->
<br><br>
<!---->

  
  <div class="sidebar-module">
    <h4>标签云</h4>
    <p class="tagcloud">
      <a href="/tags/ASP-NET/" style="font-size: 10px;">ASP.NET</a> <a href="/tags/ASP-NET-Core/" style="font-size: 11.11px;">ASP.NET Core</a> <a href="/tags/ASP-NET-Web-API笔记/" style="font-size: 10px;">ASP.NET Web API笔记</a> <a href="/tags/AngularJS/" style="font-size: 11.11px;">AngularJS</a> <a href="/tags/Asp-Net-MVC/" style="font-size: 12.22px;">Asp.Net MVC</a> <a href="/tags/EntityFramework/" style="font-size: 10px;">EntityFramework</a> <a href="/tags/Git学习/" style="font-size: 12.22px;">Git学习</a> <a href="/tags/Hexo博客搭建/" style="font-size: 17.78px;">Hexo博客搭建</a> <a href="/tags/SQL-Server/" style="font-size: 16.67px;">SQL Server</a> <a href="/tags/UWP学习笔记/" style="font-size: 11.11px;">UWP学习笔记</a> <a href="/tags/Umbraco入门/" style="font-size: 18.89px;">Umbraco入门</a> <a href="/tags/WebForm/" style="font-size: 10px;">WebForm</a> <a href="/tags/c-基础知识/" style="font-size: 14.44px;">c#基础知识</a> <a href="/tags/c-学习笔记/" style="font-size: 20px;">c#学习笔记</a> <a href="/tags/jQuery/" style="font-size: 10px;">jQuery</a> <a href="/tags/影评：其实就是观后感/" style="font-size: 13.33px;">影评：其实就是观后感</a> <a href="/tags/设计模式学习笔记/" style="font-size: 14.44px;">设计模式学习笔记</a> <a href="/tags/转载/" style="font-size: 15.56px;">转载</a> <a href="/tags/随笔/" style="font-size: 16.67px;">随笔</a>
    </p>
  </div>


  
  <div class="sidebar-module">
     <iframe width="100%" height="550" class="share_self"  frameborder="0" scrolling="no" src="http://widget.weibo.com/weiboshow/index.php?language=&width=0&height=550&fansRow=2&ptype=1&speed=0&skin=5&isTitle=1&noborder=0&isWeibo=1&isFans=1&uid=3311041262&verifier=85e63399&dpc=1"></iframe>
  </div>


  
  <div class="sidebar-module">
    <h4>友情链接</h4>
    <a href="http://www.cnblogs.com/artech/" target="_blank">Artech</a><br/>
    <a href="http://www.deepthink.pub" target="_blank">DeepThink</a><br/>
    <a href="http://edi.wang/" target="_blank">Edi.wang</a><br/>
    <a href="http://www.lanhusoft.com/Article/List" target="_blank">LanHuSoft</a><br/>
    <a href="http://www.ruanyifeng.com/blog/" target="_blank">阮一峰的网络日志</a><br/>
    <a href="http://www.cnblogs.com/shanyou/" target="_blank">张善友</a><br/>
  </div>




        </div>
    </div>
  </div>
  <footer class="blog-footer">
  <div class="container">
    <div id="footer-info" class="inner">
      &copy; 2016 Is2<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a> and <a href="https://github.com/haijiandong/haijiandong.github.io" target="_blank">GitHub</a><br/>
      Total <span id="busuanzi_value_site_pv"></span> views.  Total <span id="busuanzi_value_site_uv"></span> guests.  Total <span id="busuanzi_value_page_pv"></span> Hits.
    </div>
  </div>
</footer>

  

<script src="//cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script>


<script src="//cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>


  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css" type="text/css">
  <script src="/fancybox/jquery.fancybox.pack.js" type="text/javascript"></script>


<script src="/js/script.js" type="text/javascript"></script>

</body>
</html>